#include "server.h"
#include "queue.h"

int main()
{
    //初始化结果体
    model basic;
    sem_init(&basic.sem, 0, 0);
    sem_init(&basic.sem1, 0, 1);
    pthread_mutex_init(&basic.mutex, NULL);
    basic.queue = create_queue();

    pthread_t tid1, tid2;
    int res = 0;

    // 创建epoll监听线程
    res = pthread_create(&tid1, NULL, epoll_listen, &basic);
    if (res != 0)
    {
        printf("pthread_create1 error\n");
        return -1;
    }
    
    // 创建数据库链接线程
    res = pthread_create(&tid2, NULL, about_mysql, &basic);
    if (res != 0)
    {
        printf("pthread_create2 error\n");
        return -1;
    }
    while (1)
    {
        sleep(1);
    }
    // 回收子线程
    pthread_join(tid1, NULL);
    pthread_join(tid2, NULL);
    sem_destroy(&basic.sem);
    sem_destroy(&basic.sem1);
    pthread_mutex_destroy(&basic.mutex);
    free(basic.queue);
    return 0;
}